/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2020-12-15
 * Time: 16:31
 */

#include "ReadConfig.h"

void ReadConfig::ParseConfig(const QString& _type)
{
    QJsonDocument document = QJsonDocument::fromJson(content_);
    QJsonObject type = document.object().value(_type).toObject();

    scheme_ = type.value("scheme").toString();
    host_ = type.value("host").toString();
    port_ = type.value("port").toString();
    username_ = type.value("username").toString();
    password_ = type.value("password").toString();
}

const QString &ReadConfig::getScheme() const
{
    return scheme_;
}

const QString &ReadConfig::getPort() const
{
    return port_;
}

const QString &ReadConfig::getUsername() const
{
    return username_;
}

const QString &ReadConfig::getPassword() const
{
    return password_;
}

const QString &ReadConfig::getHost() const
{
    return host_;
}

void ReadConfig::SetFilePath(const QString& _file_path)
{
    if(_file_path.isEmpty())
        return;
    QFile file(_file_path);
    if(!file.exists())
        return;

    if(!file.open(QFile::ReadOnly))
        qDebug()<< "文件无法打开";

    content_ = file.readAll();

    ParseConfig();
}

void ReadConfig::SetContent(const QByteArray& _content)
{
    content_ = _content;

    ParseConfig();
}


